<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<html>
<head>
<title>PersistentService.jsp</title>
<style type="text/style">
.error {
color: #ff0000;
}
</style>
</head>
<body>
	<h1>PersistentService.jsp</h1>

	<p>Small demo about using PersistentService SOAP/WSDL</p>

	<p>BTW: an error of com.sun.xml.internal.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/html; charset=iso-8859-1 Supported ones are: [text/xml] might mean
		that the server crashed and return an HTML error page (not an XML SOAP message)..</p>

	<p>BTW: an javax.xml.ws.soap.SOAPFaultException: Unrecognized SOAP request. means that the required functionality on the SOAP server is missing.</p>

	<%@ page import="java.util.*"%>
	<%@ page import="java.io.*"%>
	<%@ page import="nl.boektrust.btsoep.wsimport.PersistentService.*"%>
	<%@ page import="org.slf4j.*"%>
	<%@ page import="javax.xml.ws.soap.*"%>
	<%@ page import="java.net.*"%>
	<%
		final Logger logger = LoggerFactory.getLogger(this.getClass());

		out.println("welkom to this small demo using <a href=\"" + PersistentServiceSoapService.PERSISTENTSERVICESOAPSERVICE_WSDL_LOCATION
				+ "\">wsdl</a>");//if(1==1)return;
		PersistentServiceSoapService psss = new PersistentServiceSoapService();
		
		PersistentServiceSoap pss = psss.getPersistentServiceSoapPort();
		ObjectFactory of = new ObjectFactory();
		//Person p=of.createPerson();//handled by usebean below
	%>

	<jsp:useBean id="person" class="nl.boektrust.btsoep.wsimport.PersistentService.Person" scope="page" />

	<%
		//TODO somethhing like person.biographical=param.biographical
		//TODO check null values and string,int,boolean types
		person.setBiographical(request.getParameter("biographical"));
		person.setBirthPlace(request.getParameter("birthPlace"));
		//person.setBooksContributedTo(request.getParameter("booksContributedTo")); 
		person.setDeceasedPlace(request.getParameter("deceasedPlace"));
		person.setIdentifierDai(request.getParameter("identifierDai"));
		person.setParameter("selected", request.getParameter("selected"),
				"false");
		person.setParameter("deceasedYear",
				request.getParameter("deceasedYear"), "1900");
		person.setParameter("birthYear", request.getParameter("birthYear"),
				"1950");
	%>

	<form action='' method='get'>
		<table border='1'>
			<tr>
				<th>biographical</th>
				<th>birthPlace</th>
				<th>birthYear</th>
				<th>booksContributedTo</th>
				<th>deceasedPlace</th>
				<th>deceasedYear</th>
				<th>identifierDai</th>
				<th>selected</th>
			</tr>
			<tr>
				<td><input type='text' name='biographical' value='<c:out value="${person.biographical}" />' /></td>
				<td><input type='text' name='birthPlace' value='<c:out value="${person.birthPlace}" />' /></td>
				<td><input type='text' name='birthYear' value='<c:out value="${person.birthYear}" />' /></td>
				<td><input type='text' name='booksContributedTo' value='<c:out value="${person.booksContributedTo}" />' /></td>
				<td><input type='text' name='deceasedPlace' value='<c:out value="${person.deceasedPlace}" />' /></td>
				<td><input type='text' name='deceasedYear' value='<c:out value="${person.deceasedYear}" />' /></td>
				<td><input type='text' name='identifierDai' value='<c:out value="${person.identifierDai}" />' /></td>
				<td><input type='text' name='selected' value='<c:out value="${person.selected}" />' /></td>
			</tr>
		</table>
		<input type='submit' value='Zoek'>
	</form>

	<%
		if (request.getParameter("biographical") == null) {
			out.println("<br/>skipping rest of code because biographical==null, in order to test for time outs");
			return;
		}
	%>

	<p>getAllPersons:</p>
	<%
		for (Person p : pss.getAllPersons()) {
			logger.debug("p=" + p);
			out.println("<br/>" + p);
		}
	%>


	<p>getBooksForPerson:</p>
	<%
		person.setId(123L);
		person.setBirthYear(1965);
		logger.debug("person=" + person);
		out.println("<br/>" + person);
		for (PhysicalBookManifestation pbm : pss.getBooksForPerson(person)) {
			logger.debug("pbm=" + pbm);
			out.println("<br/>" + pbm);
		}
	%>
	<p>getAllPhysicalBookManifestations:</p>
	<%
		try {
			for (PhysicalBookManifestation pbm : pss
					.getAllPhysicalBookManifestations()) {
				logger.debug("pbm=" + pbm);
				out.println("<br/>" + pbm);
			}
		} catch (SOAPFaultException e) {
			out.println("<pre style=\"color: red;\">");
			e.printStackTrace(new PrintWriter(out));
			out.println("</pre>");
		}
	%>





</body>
</html>




